#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <time.h>

#define High 480
#define Width 640
#define PI 3.14159

void main()
{
	initgraph(Width, High);
	
	int center_x,center_y;//中心坐标
	center_x = Width/2;
	center_y = High/2;
	
	int secondLength;//长度
	secondLength = Width/4;
	int minuteLength = Width/5;
	int hourLength = Width/7;
	
	int secondEnd_x,secondEnd_y;//终点坐标
	int minuteEnd_x,minuteEnd_y;
	int hourEnd_x,hourEnd_y;
	
	float secondAngel = 0,minuteAngle = 0,hourAngle = 0; //zhi针转动对应角度
	
	SYSTEMTIME ti;  //定义变量存储系统时间
	
	circle(center_x,center_y,Width/3);
	
	//outtext(center_x-25,center_y+Width/6,"我的时钟");
	
	
	
	double Angle,Lengh = Width*2/7;
	for (Angle=0;Angle<2*PI-PI/9;Angle=Angle+PI/6)
	{
		setfillcolor(WHITE);
		if (Angle==0)
		{
			fillcircle(center_x+Lengh*sin(Angle),center_y-Lengh*cos(Angle),10);
		}
		else if (Angle==PI/2)
		{
			fillcircle(center_x+Lengh*sin(Angle),center_y-Lengh*cos(Angle),10);
		}
		else if (Angle == PI)
		{
			fillcircle(center_x+Lengh*sin(Angle),center_y-Lengh*cos(Angle),10);
		}
		else if (Angle==PI*3/2)
		{
			fillcircle(center_x+Lengh*sin(Angle),center_y-Lengh*cos(Angle),10);
		}
		else
		{
			setfillcolor(RED);
			fillcircle(center_x+Lengh*sin(Angle),center_y-Lengh*cos(Angle),5);
		}
	}
	setfillcolor(WHITE);
	fillcircle(center_x,center_y+Lengh,10);
	
	BeginBatchDraw();

	while(1)
	{
		GetLocalTime(&ti);
		
		secondAngel = ti.wSecond*2*PI/60;
		minuteAngle = ti.wMinute*2*PI/60;
		hourAngle = ti.wHour*2*PI/12;
		
		secondEnd_x = center_x + secondLength*sin(secondAngel);
		secondEnd_y = center_y - secondLength*cos(secondAngel);
		
		minuteEnd_x = center_x + minuteLength*sin(minuteAngle);
		minuteEnd_y = center_y - minuteLength*cos(minuteAngle);	
		
		hourEnd_x = center_x + hourLength*sin(hourAngle);
		hourEnd_y = center_y - hourLength*cos(hourAngle);
		
		//画秒针
		setlinestyle(PS_SOLID,1);
		setcolor(WHITE);
		line(center_x,center_y,secondEnd_x,secondEnd_y);
		
		//画时针
		setlinestyle(PS_SOLID,3);
		setcolor(RED);
		line(center_x,center_y,hourEnd_x,hourEnd_y);
		
		//画分针
		setlinestyle(PS_SOLID,2);
		setcolor(GREEN);
		line(center_x,center_y,minuteEnd_x,minuteEnd_y);
		
		FlushBatchDraw();
		Sleep(50);	
		//隐藏前一个秒针	
		setcolor(BLACK);
		line(center_x,center_y,secondEnd_x,secondEnd_y);
		
		//隐藏前一个分针	
		setcolor(BLACK);
		line(center_x,center_y,minuteEnd_x,minuteEnd_y);	
		
		//隐藏前一个时针	
		setcolor(BLACK);
		line(center_x,center_y,hourEnd_x,hourEnd_y);	
		
	}
	EndBatchDraw();
	getch();
	closegraph();
}